/*
 * =====================================================================================
 *
 *       Filename:  message_redis_adapter.h
 *
 *    Description:  interface for redis adapter of correct IM message.
 *
 *        Version:  1.0
 *        Created:  2013年05月10日 13时29分27秒
 *       Revision:  none
 *       Compiler:  gcc
 *
 *         Author:  Wu Yuxin (wyx, Hin)
 *        Company:  www.Qihoo.net
 *
 * =====================================================================================
 */

#ifndef __IMSERVER_IM_MESSAGEREDISADAPTER_H__
#define __IMSERVER_IM_MESSAGEREDISADAPTER_H__

// 包含头文件
#include <stdint.h>
#include "ImServiceCommon_types.h"
#include "redis_executor/redis_executor.h"

// 前置申明
class RedisLocator;

namespace imserver {

class MessageResult;
////////////////////////////////////////////////////////////////////////////////////////
// class MessageRedisAdapter declearation
class MessageRedisAdapter {
  public:
    MessageRedisAdapter(RedisLocator *locator);
    ~MessageRedisAdapter();

    // method
    int AddImMessage(const ImMessage& msg);
    int RemoveImMessage(const int64_t sender, const int64_t receiver, const int64_t seq_id);
    int SetReadImMessage(const int64_t sender, const int64_t receiver);
    int SetReadImMessageByID(const std::vector<int64_t> & seq_ids, const int64_t uid);
    int GetOfflineImMessages(MessageResult& result, const int64_t receiver, const int32_t offset, const int32_t count);
    int GetImMessages(MessageResult& result, const int64_t sender, const int64_t receiver, const int32_t offset, const int32_t count);
    int GetOfflineImMessageCount(int32_t * count, const int64_t sender);
    void FlagRead(const int64_t sender, const int64_t receiver);
    void FlagUnread(const int64_t receiver);
  private:
    int GetMessagesFromList(MessageResult& ret, const std::string& key, const int32_t offset, const int32_t count);
    inline void Flag(const std::string& key);
    RedisExecutor redis_;
};

}

#endif
